package com.hospital.workstation.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.hospital.common.annotation.RepeatSubmit;
import com.hospital.common.annotation.Log;
import com.hospital.common.core.controller.BaseController;
import com.hospital.common.core.domain.PageQuery;
import com.hospital.common.core.domain.R;
import com.hospital.common.core.validate.AddGroup;
import com.hospital.common.core.validate.EditGroup;
import com.hospital.common.core.validate.QueryGroup;
import com.hospital.common.enums.BusinessType;
import com.hospital.common.utils.poi.ExcelUtil;
import com.hospital.workstation.domain.vo.EvidenceBasedMedicineVo;
import com.hospital.workstation.domain.bo.EvidenceBasedMedicineBo;
import com.hospital.workstation.service.IEvidenceBasedMedicineService;
import com.hospital.common.core.page.TableDataInfo;

/**
 * 循证医学相关数据
 *
 * @author hospital
 * @date 2023-03-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/workstation/evidenceBasedMedicine")
public class EvidenceBasedMedicineController extends BaseController {

    private final IEvidenceBasedMedicineService iEvidenceBasedMedicineService;

    /**
     * 查询循证医学相关数据列表
     */
    @SaCheckPermission("workstation:evidenceBasedMedicine:list")
    @GetMapping("/list")
    public TableDataInfo<EvidenceBasedMedicineVo> list(EvidenceBasedMedicineBo bo, PageQuery pageQuery) {
        return iEvidenceBasedMedicineService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取循证医学相关数据详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("workstation:evidenceBasedMedicine:query")
    @GetMapping("/{id}")
    public R<EvidenceBasedMedicineVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iEvidenceBasedMedicineService.queryById(id));
    }

    /**
     * 新增循证医学相关数据
     */
    @SaCheckPermission("workstation:evidenceBasedMedicine:add")
    @Log(title = "循证医学相关数据", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EvidenceBasedMedicineBo bo) {
        return toAjax(iEvidenceBasedMedicineService.insertByBo(bo));
    }

    /**
     * 修改循证医学相关数据
     */
    @SaCheckPermission("workstation:evidenceBasedMedicine:edit")
    @Log(title = "循证医学相关数据", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EvidenceBasedMedicineBo bo) {
        return toAjax(iEvidenceBasedMedicineService.updateByBo(bo));
    }

    /**
     * 删除循证医学相关数据
     *
     * @param ids 主键串
     */
    @SaCheckPermission("workstation:evidenceBasedMedicine:remove")
    @Log(title = "循证医学相关数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iEvidenceBasedMedicineService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
